package priv.tuyou.system.tag;

import java.util.List;

import javax.servlet.jsp.JspException;

import priv.tuyou.constants.WebContext;
import priv.tuyou.system.dao.IAdvertDao;
import priv.tuyou.system.po.Advert;
import priv.tuyou.tag.BaseTag;

/**
 * 广告标签
 * @author：涂有
 * @date 2017年1月6日 上午1:17:23
 */
public class AdvertTag extends BaseTag{

	private static final long serialVersionUID = -7118316888626049926L;
	protected IAdvertDao advertDao = WebContext.getBean(IAdvertDao.class);
	
	@Override
	public int doStartTag() throws JspException {
		
		if("getOne".equalsIgnoreCase(type) && value != null){
			
			Advert advert = dao.get(Advert.class, value);
			pageContext.setAttribute(var, advert);
		}else if("queryAll".equalsIgnoreCase(type)){//查询全部
			
			List<Advert> list = dao.queryAll(Advert.class);
			pageContext.setAttribute(var, list);
		}else if("queryRecommend".equalsIgnoreCase(type)){ //查询推荐的
			
			List<Advert> list = advertDao.queryRecommend(3);
			pageContext.setAttribute(var, list);
		}else if("queryNewest".equalsIgnoreCase(type)){ //查询最新发布的
			
			List<Advert> list = advertDao.queryNewest(5);
			pageContext.setAttribute(var, list);
		}
		return super.doStartTag();
	}
}
